using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class EnemyShootingUp : MonoBehaviour 
{

	// Use this for initialization

    //Fields
    public GameObject m_pBulletPrefab;
    
    public int m_AmountBullets;

    public Vector3 m_Direction;

    private float m_CurrentTime = 0;
    public int m_ShootForce = 500;
    public float m_FireRate = 2.0f;
    private int m_CurrentBullet = 0;
    public float m_fNextShoot = 10.0f;
    private float m_fNewShot = 0;

    public bool m_bRotation;
    float m_AngleX, m_AngleY;
    float m_SpeedX, m_SpeedY;

	void Start () 
    {
        m_AngleX = 0;
        m_AngleY = 1;
        m_SpeedX = 0.1f;
        m_SpeedY = -0.1f;
	}
	
	// Update is called once per frame
	void Update () 
    {
        
       

        if (m_CurrentBullet <= m_AmountBullets)
        {
            if (Time.time > m_CurrentTime)
            {
                m_CurrentTime = Time.time + m_FireRate;
                m_fNewShot = m_CurrentTime;
                GameObject BulletPtr = Instantiate(m_pBulletPrefab, transform.position, Quaternion.identity)as GameObject;

                if (m_bRotation)
                {
                    BulletPtr.rigidbody.AddForce(new Vector3(m_AngleX,m_AngleY,0).normalized * m_ShootForce);
                    m_AngleX += m_SpeedX;
                    m_AngleY += m_SpeedY;

                    if (m_AngleY < -1)
                    {
                        m_SpeedY *= -1;
                    }
                    if (m_AngleY > 1)
                    {
                        m_SpeedY *= -1;
                    }
                    if (m_AngleX < -1)
                    {
                        m_SpeedX *= -1;
                    }
                    if (m_AngleX > 1)
                    {
                        m_SpeedX *= -1;
                    }
                    
                }
                else
                {
                    BulletPtr.rigidbody.AddForce(m_Direction * m_ShootForce);
                }
                
                ++m_CurrentBullet;
            }

           
        }



        if (Time.time > m_fNextShoot + m_fNewShot)
        {
            m_CurrentBullet = 0;
        }
       
	
	}

    
}
